﻿namespace WMS6.BLL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.IDAL;
    using WMS6.QueryEntity;
    using WMS6.DALFactory;

    public class InvLotLocLpnBLL
    {
        private static readonly ICommonMethodDA commonMethod = DataAccess.CreateCommonMethod();
        private List<string> dataBaseID;
        private static readonly IInvLotLocLpnDA invLotLocLpn = DataAccess.CreateInvLotLocLpnDA();
        private PubParasInfo pubParasInfo;

        public InvLotLocLpnBLL()
        {
            this.pubParasInfo = null;
        }

        public InvLotLocLpnBLL(string currentWH)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(currentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(currentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001");
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002");
            }
        }

        public InvLotLocLpnBLL(PubParasInfo tempPubParasInfo)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(tempPubParasInfo.CurrentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(tempPubParasInfo.CurrentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001", this.pubParasInfo.UserLanguage);
                }
                else
                {
                    this.pubParasInfo = new PubParasInfo();
                    this.pubParasInfo = tempPubParasInfo;
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002", this.pubParasInfo.UserLanguage);
            }
        }

        public InvLotLocLpnInfo GetInvLotLocLpnByID(string lot, string loc, string lpnID)
        {
            return invLotLocLpn.GetInvLotLocLpnByID(lot, loc, lpnID, this.dataBaseID[0]);
        }

        public DataSet GetInvLotLocLpnByQueryEntity(InvLotLocLpnQueryEntity LotLocLpnEntity)
        {
            List<string> sqlWhere = new List<string>();
            if (!string.IsNullOrEmpty(LotLocLpnEntity.Lot))
            {
                sqlWhere.Add(" A.LOT " + LotLocLpnEntity.Lot);
            }
            if (!string.IsNullOrEmpty(LotLocLpnEntity.Loc))
            {
                sqlWhere.Add(" A.LOC " + LotLocLpnEntity.Loc);
            }
            if (!string.IsNullOrEmpty(LotLocLpnEntity.OwnerID))
            {
                sqlWhere.Add(" A.OWNER_ID " + LotLocLpnEntity.OwnerID);
            }
            if (!string.IsNullOrEmpty(LotLocLpnEntity.SkuID))
            {
                sqlWhere.Add(" A.SKU_ID " + LotLocLpnEntity.SkuID);
            }
            if (!string.IsNullOrEmpty(LotLocLpnEntity.LpnID))
            {
                sqlWhere.Add(" A.LPN_ID " + LotLocLpnEntity.LpnID);
            }
            if (!string.IsNullOrEmpty(LotLocLpnEntity.ReceiptID))
            {
                sqlWhere.Add(" L.LOT_ATTR10 " + LotLocLpnEntity.ReceiptID);
            }
            if (!string.IsNullOrEmpty(LotLocLpnEntity.ExternalReceiptID))
            {
                sqlWhere.Add(" R.EXTERNAL_RECEIPT_ID " + LotLocLpnEntity.ExternalReceiptID);
            }
            if (!string.IsNullOrEmpty(LotLocLpnEntity.ReceiptDate))
            {
                sqlWhere.Add(" CONVERT(VARCHAR(25),L.RECEIPT_DATE,121) " + LotLocLpnEntity.ReceiptDate);
            }
            if (!string.IsNullOrEmpty(LotLocLpnEntity.VendorID))
            {
                sqlWhere.Add(" L.VENDOR_ID " + LotLocLpnEntity.VendorID);
            }
            if (!string.IsNullOrEmpty(LotLocLpnEntity.ExternalLot))
            {
                sqlWhere.Add(" L.EXTERNAL_LOT " + LotLocLpnEntity.ExternalLot);
            }
            if (!string.IsNullOrEmpty(LotLocLpnEntity.ProduceDate))
            {
                sqlWhere.Add(" CONVERT(VARCHAR(25),L.PRODUCE_DATE,121) " + LotLocLpnEntity.ProduceDate);
            }
            if (!string.IsNullOrEmpty(LotLocLpnEntity.ExpiryDate))
            {
                sqlWhere.Add(" CONVERT(VARCHAR(25),L.EXPIRY_DATE,121) " + LotLocLpnEntity.ExpiryDate);
            }
            if (!string.IsNullOrEmpty(LotLocLpnEntity.LotAttr01))
            {
                sqlWhere.Add(" L.LOT_ATTR01 " + LotLocLpnEntity.LotAttr01);
            }
            if (!string.IsNullOrEmpty(LotLocLpnEntity.LotAttr02))
            {
                sqlWhere.Add(" L.LOT_ATTR02 " + LotLocLpnEntity.LotAttr02);
            }
            if (!string.IsNullOrEmpty(LotLocLpnEntity.LotAttr03))
            {
                sqlWhere.Add(" L.LOT_ATTR03 " + LotLocLpnEntity.LotAttr03);
            }
            if (!string.IsNullOrEmpty(LotLocLpnEntity.LotAttr04))
            {
                sqlWhere.Add(" L.LOT_ATTR04 " + LotLocLpnEntity.LotAttr04);
            }
            if (!string.IsNullOrEmpty(LotLocLpnEntity.LotAttr05))
            {
                sqlWhere.Add(" L.LOT_ATTR05 " + LotLocLpnEntity.LotAttr05);
            }
            if (!string.IsNullOrEmpty(LotLocLpnEntity.LotAttr06))
            {
                sqlWhere.Add(" L.LOT_ATTR06 " + LotLocLpnEntity.LotAttr06);
            }
            if (!string.IsNullOrEmpty(LotLocLpnEntity.LotAttr07))
            {
                sqlWhere.Add(" L.LOT_ATTR07 " + LotLocLpnEntity.LotAttr07);
            }
            if (!string.IsNullOrEmpty(LotLocLpnEntity.LotAttr08))
            {
                sqlWhere.Add(" L.LOT_ATTR08 " + LotLocLpnEntity.LotAttr08);
            }
            if (!string.IsNullOrEmpty(LotLocLpnEntity.LotAttr09))
            {
                sqlWhere.Add(" L.LOT_ATTR09 " + LotLocLpnEntity.LotAttr09);
            }
            if (!string.IsNullOrEmpty(LotLocLpnEntity.LotAttr10))
            {
                sqlWhere.Add(" L.LOT_ATTR10 " + LotLocLpnEntity.LotAttr10);
            }
            if (!string.IsNullOrEmpty(LotLocLpnEntity.Status))
            {
                sqlWhere.Add(" A.STATUS " + LotLocLpnEntity.Status);
            }
            if (!string.IsNullOrEmpty(LotLocLpnEntity.SkuDescr))
            {
                sqlWhere.Add(" B.DESCR " + LotLocLpnEntity.SkuDescr);
            }
            if (!string.IsNullOrEmpty(LotLocLpnEntity.SkuClass))
            {
                sqlWhere.Add(" B.SKU_CLASS_ID " + LotLocLpnEntity.SkuClass);
            }
            if (!string.IsNullOrEmpty(LotLocLpnEntity.Qty))
            {
                sqlWhere.Add(" A.QTY " + LotLocLpnEntity.Qty);
                sqlWhere.Add(" A.QTY-A.ALLOCATED_QTY-A.PICKED_QTY-A.EXPECTED_QTY- A.PICKINPROCESS_QTY- A.PENDING_MOVE_IN > 0 ");
            }
            return invLotLocLpn.GetInvLotLocLpnByQueryList(sqlWhere, LotLocLpnEntity, this.dataBaseID[0], this.pubParasInfo);
        }
    }
}

